﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwArtiklStanjeuSkladistuProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwArtiklStanjeuSkladistuProviderBaseCore : EntityViewProviderBase<VwArtiklStanjeuSkladistu>
	{
		#region Custom Methods
		
		
		#region _vwArtiklStanjeuSkladistu_Get_Stanje_DatumDo
		
		/// <summary>
		///	This method wrap the '_vwArtiklStanjeuSkladistu_Get_Stanje_DatumDo' stored procedure. 
		/// </summary>
		/// <param name="IDOrg"> A <c>System.Int32?</c> instance.</param>
		/// <param name="IDArtikl"> A <c>System.Int32?</c> instance.</param>
		/// <param name="DatumDo"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/> instance.</returns>
		public VList<VwArtiklStanjeuSkladistu> Get_Stanje_DatumDo(System.Int32? @IDOrg, System.Int32? @IDArtikl, System.DateTime? @DatumDo)
		{
			return Get_Stanje_DatumDo(null, 0, int.MaxValue , @IDOrg, @IDArtikl, @DatumDo);
		}
		
		/// <summary>
		///	This method wrap the '_vwArtiklStanjeuSkladistu_Get_Stanje_DatumDo' stored procedure. 
		/// </summary>
		/// <param name="IDOrg"> A <c>System.Int32?</c> instance.</param>
		/// <param name="IDArtikl"> A <c>System.Int32?</c> instance.</param>
		/// <param name="DatumDo"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/> instance.</returns>
		public VList<VwArtiklStanjeuSkladistu> Get_Stanje_DatumDo(int start, int pageLength, System.Int32? @IDOrg, System.Int32? @IDArtikl, System.DateTime? @DatumDo)
		{
			return Get_Stanje_DatumDo(null, start, pageLength , @IDOrg, @IDArtikl, @DatumDo);
		}
				
		/// <summary>
		///	This method wrap the '_vwArtiklStanjeuSkladistu_Get_Stanje_DatumDo' stored procedure. 
		/// </summary>
		/// <param name="IDOrg"> A <c>System.Int32?</c> instance.</param>
		/// <param name="IDArtikl"> A <c>System.Int32?</c> instance.</param>
		/// <param name="DatumDo"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/> instance.</returns>
		public VList<VwArtiklStanjeuSkladistu> Get_Stanje_DatumDo(TransactionManager transactionManager, System.Int32? @IDOrg, System.Int32? @IDArtikl, System.DateTime? @DatumDo)
		{
			return Get_Stanje_DatumDo(transactionManager, 0, int.MaxValue , @IDOrg, @IDArtikl, @DatumDo);
		}
		
		/// <summary>
		///	This method wrap the '_vwArtiklStanjeuSkladistu_Get_Stanje_DatumDo' stored procedure. 
		/// </summary>
		/// <param name="IDOrg"> A <c>System.Int32?</c> instance.</param>
		/// <param name="IDArtikl"> A <c>System.Int32?</c> instance.</param>
		/// <param name="DatumDo"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/> instance.</returns>
		public abstract VList<VwArtiklStanjeuSkladistu> Get_Stanje_DatumDo(TransactionManager transactionManager, int start, int pageLength , System.Int32? @IDOrg, System.Int32? @IDArtikl, System.DateTime? @DatumDo);
		
		#endregion
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwArtiklStanjeuSkladistu&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/></returns>
		protected static VList&lt;VwArtiklStanjeuSkladistu&gt; Fill(DataSet dataSet, VList<VwArtiklStanjeuSkladistu> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwArtiklStanjeuSkladistu>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwArtiklStanjeuSkladistu&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwArtiklStanjeuSkladistu>"/></returns>
		protected static VList&lt;VwArtiklStanjeuSkladistu&gt; Fill(DataTable dataTable, VList<VwArtiklStanjeuSkladistu> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwArtiklStanjeuSkladistu c = new VwArtiklStanjeuSkladistu();
					c.IDArtikl = (Convert.IsDBNull(row["IDArtikl"]))?(int)0:(System.Int32?)row["IDArtikl"];
					c.Artikl = (Convert.IsDBNull(row["Artikl"]))?string.Empty:(System.String)row["Artikl"];
					c.IDSkladiste = (Convert.IsDBNull(row["IDSkladiste"]))?(int)0:(System.Int32)row["IDSkladiste"];
					c.Skladiste = (Convert.IsDBNull(row["Skladiste"]))?string.Empty:(System.String)row["Skladiste"];
					c.Stanje = (Convert.IsDBNull(row["Stanje"]))?0.0f:(System.Double?)row["Stanje"];
					c.Rezervirano = (Convert.IsDBNull(row["Rezervirano"]))?0.0f:(System.Double?)row["Rezervirano"];
					c.Predracun = (Convert.IsDBNull(row["Predracun"]))?0.0f:(System.Double?)row["Predracun"];
					c.IDOrganizacijaOd = (Convert.IsDBNull(row["IDOrganizacijaOd"]))?(int)0:(System.Int32?)row["IDOrganizacijaOd"];
					c.VPC = (Convert.IsDBNull(row["VPC"]))?0:(System.Decimal?)row["VPC"];
					c.MPC = (Convert.IsDBNull(row["MPC"]))?0.0F:(System.Single?)row["MPC"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwArtiklStanjeuSkladistu&gt;"/></returns>
		protected VList<VwArtiklStanjeuSkladistu> Fill(IDataReader reader, VList<VwArtiklStanjeuSkladistu> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwArtiklStanjeuSkladistu entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwArtiklStanjeuSkladistu>("VwArtiklStanjeuSkladistu",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwArtiklStanjeuSkladistu();
					}
					entity.IDArtikl = reader.IsDBNull(reader.GetOrdinal("IDArtikl")) ? null : (System.Int32?)reader["IDArtikl"];
					//entity.IDArtikl = (Convert.IsDBNull(reader["IDArtikl"]))?(int)0:(System.Int32?)reader["IDArtikl"];
					entity.Artikl = reader.IsDBNull(reader.GetOrdinal("Artikl")) ? null : (System.String)reader["Artikl"];
					//entity.Artikl = (Convert.IsDBNull(reader["Artikl"]))?string.Empty:(System.String)reader["Artikl"];
					entity.IDSkladiste = (System.Int32)reader["IDSkladiste"];
					//entity.IDSkladiste = (Convert.IsDBNull(reader["IDSkladiste"]))?(int)0:(System.Int32)reader["IDSkladiste"];
					entity.Skladiste = reader.IsDBNull(reader.GetOrdinal("Skladiste")) ? null : (System.String)reader["Skladiste"];
					//entity.Skladiste = (Convert.IsDBNull(reader["Skladiste"]))?string.Empty:(System.String)reader["Skladiste"];
					entity.Stanje = reader.IsDBNull(reader.GetOrdinal("Stanje")) ? null : (System.Double?)reader["Stanje"];
					//entity.Stanje = (Convert.IsDBNull(reader["Stanje"]))?0.0f:(System.Double?)reader["Stanje"];
					entity.Rezervirano = reader.IsDBNull(reader.GetOrdinal("Rezervirano")) ? null : (System.Double?)reader["Rezervirano"];
					//entity.Rezervirano = (Convert.IsDBNull(reader["Rezervirano"]))?0.0f:(System.Double?)reader["Rezervirano"];
					entity.Predracun = reader.IsDBNull(reader.GetOrdinal("Predracun")) ? null : (System.Double?)reader["Predracun"];
					//entity.Predracun = (Convert.IsDBNull(reader["Predracun"]))?0.0f:(System.Double?)reader["Predracun"];
					entity.IDOrganizacijaOd = reader.IsDBNull(reader.GetOrdinal("IDOrganizacijaOd")) ? null : (System.Int32?)reader["IDOrganizacijaOd"];
					//entity.IDOrganizacijaOd = (Convert.IsDBNull(reader["IDOrganizacijaOd"]))?(int)0:(System.Int32?)reader["IDOrganizacijaOd"];
					entity.VPC = reader.IsDBNull(reader.GetOrdinal("VPC")) ? null : (System.Decimal?)reader["VPC"];
					//entity.VPC = (Convert.IsDBNull(reader["VPC"]))?0:(System.Decimal?)reader["VPC"];
					entity.MPC = reader.IsDBNull(reader.GetOrdinal("MPC")) ? null : (System.Single?)reader["MPC"];
					//entity.MPC = (Convert.IsDBNull(reader["MPC"]))?0.0F:(System.Single?)reader["MPC"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwArtiklStanjeuSkladistu"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklStanjeuSkladistu"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwArtiklStanjeuSkladistu entity)
		{
			reader.Read();
			entity.IDArtikl = reader.IsDBNull(reader.GetOrdinal("IDArtikl")) ? null : (System.Int32?)reader["IDArtikl"];
			//entity.IDArtikl = (Convert.IsDBNull(reader["IDArtikl"]))?(int)0:(System.Int32?)reader["IDArtikl"];
			entity.Artikl = reader.IsDBNull(reader.GetOrdinal("Artikl")) ? null : (System.String)reader["Artikl"];
			//entity.Artikl = (Convert.IsDBNull(reader["Artikl"]))?string.Empty:(System.String)reader["Artikl"];
			entity.IDSkladiste = (System.Int32)reader["IDSkladiste"];
			//entity.IDSkladiste = (Convert.IsDBNull(reader["IDSkladiste"]))?(int)0:(System.Int32)reader["IDSkladiste"];
			entity.Skladiste = reader.IsDBNull(reader.GetOrdinal("Skladiste")) ? null : (System.String)reader["Skladiste"];
			//entity.Skladiste = (Convert.IsDBNull(reader["Skladiste"]))?string.Empty:(System.String)reader["Skladiste"];
			entity.Stanje = reader.IsDBNull(reader.GetOrdinal("Stanje")) ? null : (System.Double?)reader["Stanje"];
			//entity.Stanje = (Convert.IsDBNull(reader["Stanje"]))?0.0f:(System.Double?)reader["Stanje"];
			entity.Rezervirano = reader.IsDBNull(reader.GetOrdinal("Rezervirano")) ? null : (System.Double?)reader["Rezervirano"];
			//entity.Rezervirano = (Convert.IsDBNull(reader["Rezervirano"]))?0.0f:(System.Double?)reader["Rezervirano"];
			entity.Predracun = reader.IsDBNull(reader.GetOrdinal("Predracun")) ? null : (System.Double?)reader["Predracun"];
			//entity.Predracun = (Convert.IsDBNull(reader["Predracun"]))?0.0f:(System.Double?)reader["Predracun"];
			entity.IDOrganizacijaOd = reader.IsDBNull(reader.GetOrdinal("IDOrganizacijaOd")) ? null : (System.Int32?)reader["IDOrganizacijaOd"];
			//entity.IDOrganizacijaOd = (Convert.IsDBNull(reader["IDOrganizacijaOd"]))?(int)0:(System.Int32?)reader["IDOrganizacijaOd"];
			entity.VPC = reader.IsDBNull(reader.GetOrdinal("VPC")) ? null : (System.Decimal?)reader["VPC"];
			//entity.VPC = (Convert.IsDBNull(reader["VPC"]))?0:(System.Decimal?)reader["VPC"];
			entity.MPC = reader.IsDBNull(reader.GetOrdinal("MPC")) ? null : (System.Single?)reader["MPC"];
			//entity.MPC = (Convert.IsDBNull(reader["MPC"]))?0.0F:(System.Single?)reader["MPC"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwArtiklStanjeuSkladistu"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklStanjeuSkladistu"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwArtiklStanjeuSkladistu entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDArtikl = (Convert.IsDBNull(dataRow["IDArtikl"]))?(int)0:(System.Int32?)dataRow["IDArtikl"];
			entity.Artikl = (Convert.IsDBNull(dataRow["Artikl"]))?string.Empty:(System.String)dataRow["Artikl"];
			entity.IDSkladiste = (Convert.IsDBNull(dataRow["IDSkladiste"]))?(int)0:(System.Int32)dataRow["IDSkladiste"];
			entity.Skladiste = (Convert.IsDBNull(dataRow["Skladiste"]))?string.Empty:(System.String)dataRow["Skladiste"];
			entity.Stanje = (Convert.IsDBNull(dataRow["Stanje"]))?0.0f:(System.Double?)dataRow["Stanje"];
			entity.Rezervirano = (Convert.IsDBNull(dataRow["Rezervirano"]))?0.0f:(System.Double?)dataRow["Rezervirano"];
			entity.Predracun = (Convert.IsDBNull(dataRow["Predracun"]))?0.0f:(System.Double?)dataRow["Predracun"];
			entity.IDOrganizacijaOd = (Convert.IsDBNull(dataRow["IDOrganizacijaOd"]))?(int)0:(System.Int32?)dataRow["IDOrganizacijaOd"];
			entity.VPC = (Convert.IsDBNull(dataRow["VPC"]))?0:(System.Decimal?)dataRow["VPC"];
			entity.MPC = (Convert.IsDBNull(dataRow["MPC"]))?0.0F:(System.Single?)dataRow["MPC"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwArtiklStanjeuSkladistuFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklStanjeuSkladistu"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklStanjeuSkladistuFilterBuilder : SqlFilterBuilder<VwArtiklStanjeuSkladistuColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeuSkladistuFilterBuilder class.
		/// </summary>
		public VwArtiklStanjeuSkladistuFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeuSkladistuFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklStanjeuSkladistuFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeuSkladistuFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklStanjeuSkladistuFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklStanjeuSkladistuFilterBuilder

	#region VwArtiklStanjeuSkladistuParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklStanjeuSkladistu"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklStanjeuSkladistuParameterBuilder : ParameterizedSqlFilterBuilder<VwArtiklStanjeuSkladistuColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeuSkladistuParameterBuilder class.
		/// </summary>
		public VwArtiklStanjeuSkladistuParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeuSkladistuParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklStanjeuSkladistuParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeuSkladistuParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklStanjeuSkladistuParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklStanjeuSkladistuParameterBuilder
} // end namespace
